<script>
    function ajax(url, callback) {
        //面向框架，面向扩展包开发
        const xhr = new XMLHttpRequest()
        //配置环节
        xhr.open('GET', url)
        xhr.responseType = 'json'
        //真正发送
        xhr.send()
        //发送完毕处理结果
        xhr.onload = () => {
            if (xhr.status == 200) {
                callback(xhr.response)
            } else {
                console.log(`${xhr.status} : ${xhr.responseText}`)
            }
        }
    }
    ajax('hd.php', response => {
        console.log(response)
        appendElemnt(response)
        // const articles = JSON.parse(response)
        // console.log(articles[0].title)
    })

    function appendElemnt(data) {
        const ul = document.createElement('ul')
        data.map(item => {
            const li = document.createElement('li')
            li.textContent = item.title
            ul.insertAdjacentElement('beforeend', li)
        })
        document.body.appendChild(ul)
    }
</script>
